package client;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import customLayouts.VerticalFlowLayout;

public class SettingsWindow extends JFrame {
	// the variable
	private static final long serialVersionUID = 1L;
	private JFrame tab3 = new JFrame();
	private JTextField iptxt = new JTextField();
	private JTextField porttxt = new JTextField();
	private JButton submit = new JButton("Submit");
	private JLabel txt = new JLabel("Vul ip in: ");
	private JLabel txt2 = new JLabel("Vul poort in: ");
	private JLabel result = new JLabel();
	private JLabel results = new JLabel();
	private JPanel panel = new JPanel();
	private String ipadress;
	private String portadress;

	public SettingsWindow() {
		// the layout of the components (size, position)
		tab3.setSize(250, 250);
		tab3.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		panel.setLayout(new VerticalFlowLayout());
		iptxt.setSize(100, 15);
		porttxt.setSize(100, 15);
		porttxt.setLocation(70, 40);
		txt2.setLocation(80, 40);
		submit.setLocation(60, 50);
		result.setLocation(90, 40);
		results.setLocation(100, 40);
		
		// if pressed change the url of the label and store it in the config
		// file
		submit.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				result.setText(iptxt.getText());
				results.setText(porttxt.getText());
				ipadress = iptxt.getText();
				portadress = porttxt.getText();
				SystemProperties.setServerIp(ipadress);
				SystemProperties.setServerPort(portadress);
			}
		});
		// adding the labels buttons etc.
		panel.add(txt);
		panel.add(txt2);
		panel.add(result);
		panel.add(results);
		panel.add(iptxt);
		panel.add(porttxt);
		panel.add(submit);
		tab3.add(panel);
		tab3.setVisible(true);
	}
}